//
//  GrantDetailsViewController.m
//  DistributorAB
//
//  Created by Huazhi_xi on 2021/1/27.
//  Copyright © 2021 Master Maid. All rights reserved.
//

#import "GrantDetailsViewController.h"
#import "OnlyImageCollectionViewCell.h"

static NSString *const OnlyImageCollectionViewCellID = @"OnlyImageCollectionViewCell";

@interface GrantDetailsViewController ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
@property (weak, nonatomic) IBOutlet UIImageView *statusImageView;
@property (weak, nonatomic) IBOutlet UILabel *resultLbl;
@property (weak, nonatomic) IBOutlet UILabel *nameLbl;
@property (weak, nonatomic) IBOutlet UILabel *typeLbl;
@property (weak, nonatomic) IBOutlet UILabel *priceLbl;
@property (weak, nonatomic) IBOutlet UILabel *installTimeLbl;
@property (weak, nonatomic) IBOutlet UICollectionView *installCollectionView;

@property (weak, nonatomic) IBOutlet UILabel *applyTimeLbl;
@property (weak, nonatomic) IBOutlet UILabel *descLbl;
@property (weak, nonatomic) IBOutlet UICollectionView *guZhangCollectionView;
/**     */
@property (strong, nonatomic) NSArray *installImageArray;
/**     */
@property (strong, nonatomic) NSArray *guZhangImageArray;
@end

@implementation GrantDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupView];
}
#pragma mark - 私有方法
-(void)setupView {
    self.title = @"补助金详情";
    self.view.backgroundColor = Main_BackGroundColor;
    [self.leftbutton setImage:imgname(@"left_icon") forState:(UIControlStateNormal)];
    
    if ([_model.status isEqual:@"-1"]) {//1，2成功，-1失败
        _statusImageView.image = [UIImage imageNamed:@"gr_failure_icon"];
    } else if ([_model.status isEqual:@"0"]) {
        _statusImageView.image = [UIImage imageNamed:@"gr_stay_icon"];
    } else {
        _statusImageView.image = [UIImage imageNamed:@"gr_success_icon"];
    }
    _resultLbl.text = _model.auditContent;
    _nameLbl.text = _model.parts_name;
    _typeLbl.text = _model.att_name;
    _priceLbl.text = [NSString stringWithFormat:@"￥%@", _model.compensationPrice];
    _installTimeLbl.text = _model.installDate;
    _applyTimeLbl.text = _model.createTime;
    _descLbl.text = _model.faultDetails;
    _installImageArray = [_model.installImg componentsSeparatedByString:@"|"];
    _guZhangImageArray = [_model.faultImg componentsSeparatedByString:@"|"];
    
    [_installCollectionView registerNib:[UINib nibWithNibName:OnlyImageCollectionViewCellID bundle:nil] forCellWithReuseIdentifier:OnlyImageCollectionViewCellID];
    [_guZhangCollectionView registerNib:[UINib nibWithNibName:OnlyImageCollectionViewCellID bundle:nil] forCellWithReuseIdentifier:OnlyImageCollectionViewCellID];
    
}
- (IBAction)backClick {
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - UICollectionViewDelegate, UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    if (collectionView == _installCollectionView) {
        return _installImageArray.count;
    }
    return _guZhangImageArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    OnlyImageCollectionViewCell *imgCell = [collectionView dequeueReusableCellWithReuseIdentifier:OnlyImageCollectionViewCellID forIndexPath:indexPath];
    if (collectionView == _installCollectionView) {
        [imgCell.upImageView sd_setImageWithURL:[NSURL URLWithString:_installImageArray[indexPath.row]] placeholderImage:[UIImage imageNamed:@"goodsPlaceHolderImage"]];
    } else {
        [imgCell.upImageView sd_setImageWithURL:[NSURL URLWithString:_guZhangImageArray[indexPath.row]] placeholderImage:[UIImage imageNamed:@"goodsPlaceHolderImage"]];
    }
    return imgCell;
}
#pragma mark - UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake(60, 60);
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return 0;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return 0;
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(0, 0, 0, 0);
}
#pragma mark - 懒加载
- (NSArray *)installImageArray {
    if (!_installImageArray) {
        _installImageArray  = [[NSArray alloc] init];
    }
    return _installImageArray;
}
- (NSArray *)guZhangImageArray {
    if (!_guZhangImageArray) {
        _guZhangImageArray  = [[NSArray alloc] init];
    }
    return _guZhangImageArray;
}
@end
